// yarn add -D strip-html-comments comment-stripper
const fs = require('fs')
const path = require('path')
const { strip } = require('comment-stripper')
const stripHtmlComments = require('strip-html-comments')

function removeCommentsFromFile(filePath) {
  let data = fs.readFileSync(filePath, 'utf8')
  // data = data.replace(/^\/\*[\s\S]+?\*\/|^\/\/.*/g, '')
  data = stripHtmlComments(data)
  data = strip(data)
  fs.writeFileSync(filePath, data)
  console.log('clear ok:', filePath)
}

function processFilesInDirectory(dirPath) {
  const files = fs.readdirSync(dirPath)
  files.forEach(file => {
    const filePath = path.join(dirPath, file)
    const stat = fs.lstatSync(filePath)
    if (stat.isDirectory()) {
      processFilesInDirectory(filePath)
    } else if (file.endsWith('.js') || file.endsWith('.vue')) {
      removeCommentsFromFile(filePath)
    }
  })
}

processFilesInDirectory('../chery-jaecoo-global-java-ui/')
console.log('注释清除完成！')